# coding:utf-8

from PySide6.QtCore import QObject, Signal, Slot


class Human(QObject):
    # 带str参数的信号
    nameChanged = Signal(str)
    # overload型 信号, int 或 str参数
    ageChanged = Signal((int,), (str,))

    def __init__(self, parent=None):
        super().__init__(parent)
        self.__age: int = None
        self.__name: str = None

    def setName(self, name: str):
        self.__name = name
        # 带了参数 触发
        self.nameChanged.emit(self.__name)

    def setAge(self, age: int):
        self.__age = age
        # 带了参数 触发
        self.ageChanged[int].emit(age)
        self.ageChanged[str].emit(str(age))


class Responsor(QObject):
    # 1个slot函数 接受参数str
    @Slot(str)
    def do_nameChanged(self, name):
        print(f"slot called, name is {name}")

    @Slot(str)
    def do_ageChanged_str(self, ageInfo: str):
        print(f"slot, age info is {ageInfo}")

    # 2个slot函数 接受参数int, str
    @Slot(int)
    def do_ageChanged_int(self, age: int):
        print(f"slot called, age is {age}")


if __name__ == '__main__':
    boy = Human()
    call = Responsor()
    boy.nameChanged.connect(call.do_nameChanged)
    boy.ageChanged.connect(call.do_ageChanged_int)
    boy.ageChanged[str].connect(call.do_ageChanged_str)

    print("建立关联后")
    boy.setName("Alice")
    boy.setAge(12)
